﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;

using NUnit.Framework;

using Refix.Core;

using Configuration = Refix.Core.Configuration;

namespace Refix.Console.Tests
{
    [TestFixture]
    public class ProgramTest
    {
        [TestFixtureSetUp]
        public virtual void TextFixtureSetUp()
        {
            ConfigurationManager.AppSettings.Set("Refix.Repository.Local", null);
            ConfigurationManager.AppSettings.Set("Refix.Repository.Remote", null);
            Environment.SetEnvironmentVariable(EnvironmentVariables.RefixLocalRepository, null,
                                               EnvironmentVariableTarget.Process);
            Environment.SetEnvironmentVariable(EnvironmentVariables.RefixRemoteRepository, null,
                                               EnvironmentVariableTarget.Process);
            Configuration.Refresh();
        }

        [Test]
        public void Main_Missing_Configuration_Returns_Appropriate_Status()
        {
            ConfigurationManager.AppSettings.Set("Refix.Repository.Local", null);
            Configuration.Refresh();
            int result = Program.Main(new string[0]);
            Assert.AreEqual(Program.CONFIGURATION_FAILURE, result,
                            "Missing configuration should have returned a configuration failure result.");
        }

        [Test]
        public void Main_Invalid_Arguments_Returns_Appropriate_Status()
        {
            ConfigurationManager.AppSettings.Set("Refix.Repository.Local", ".testrefixrepo");
            Configuration.Refresh();
            int result = Program.Main(new[] { "clean", "-qv" });
            Assert.AreEqual(Program.VALIDATION_FAILURE, result,
                            "Missing configuration should have returned a validation failure result.");
        }

        [Test]
        public void Main_Failing_Execution_Returns_Appropriate_Status()
        {
            ConfigurationManager.AppSettings.Set("Refix.Repository.Local", ".testrefixrepo");
            Configuration.Refresh();
            int result = Program.Main(new[] { "reg", "*.poipoipoi" });
            Assert.AreEqual(Program.EXECUTION_FAILURE, result,
                            "Failing execution should have returned an execution failure result.");
        }
    }
}
